var logger = require('log4js').getLogger('services');

var http = require('http'),
    Faye = require('faye'),
    PORT = 3344

var server = http.createServer(),
    bayeux = new Faye.NodeAdapter({mount: '/events', timeout: 45});

bayeux.on('subscribe', function (clientId, channel) {
    console.log('[SUBSCRIBE] ' + clientId + ' -> ' + channel);
});

bayeux.on('unsubscribe', function (clientId, channel) {
    console.log('[UNSUBSCRIBE] ' + clientId + ' -> ' + channel);
});

bayeux.on('disconnect', function (clientId) {
    console.log('[DISCONNECT] ' + clientId);
});

bayeux.attach(server);
server.listen(PORT);
server.on('error', function (err) {
    console.log(err)
    console.error('error');
    process.exit(1);
});
logger.info('message_server', PORT)